package net.lab1024.sa.admin.module.business.traffic.aibi.service;

import java.time.LocalDateTime;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.business.traffic.aibi.dao.AibiCarQueueDao;
import net.lab1024.sa.admin.module.business.traffic.aibi.domain.entity.AibiCarQueueEntity;
import net.lab1024.sa.admin.module.business.traffic.aibi.domain.form.AibiCarQueueQueryForm;
import net.lab1024.sa.admin.module.business.traffic.aibi.domain.vo.AibiCarQueueVO;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.util.SmartPageUtil;

/**
 * Aibi 摄像机排队数据服务
 */
@Service
public class AibiCarQueueService {

    @Resource
    private AibiCarQueueDao aibiCarQueueDao;

    /**
     * 批量保存数据（带 upsert）
     */
    public void saveBatch(List<AibiCarQueueEntity> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return;
        }
        LocalDateTime now = LocalDateTime.now();
        entityList.forEach(entity -> {
            if (entity.getCreateTime() == null) {
                entity.setCreateTime(now);
            }
            entity.setUpdateTime(now);
        });
        aibiCarQueueDao.insertOrUpdateBatch(entityList);
    }

    /**
     * 分页查询
     */
    public PageResult<AibiCarQueueVO> queryPage(AibiCarQueueQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AibiCarQueueVO> list = aibiCarQueueDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }
}

